package org.hot100_3;

import com.sun.security.auth.UnixNumericGroupPrincipal;

import java.util.HashSet;

public class leetcode160 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {

        HashSet<ListNode> hashSet = new HashSet<>();

        ListNode temp = headA;

        while (temp!=null){
            hashSet.add(temp);
            temp=temp.next;
        }

        temp = headB;

        while (temp!= null){
            if (hashSet.contains(temp)){
                return temp;
            }
            temp=temp.next;
        }

        return null;
    }
}
